Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

235
Views
There is an additional "[" in json, which is not feched by response

The Json i am getting from API getUrl is not executed in my function I want to get weather.main

{
  "coord":{
            "lon":88.3697,
            "lat":22.5697
          },
  "weather":[
              {
                "id":721,
                "main":"Haze",
                "description":
                "haze",
                "icon":"50n"
              }
            ],
   "base":"stations",
   "main":{
            "temp":27.97,
            "feels_like":32.49,
            "temp_min":27.97,
            "temp_max":27.97,
            "pressure":1005,
            "humidity":83
          },
 }

My Script =>

const url = `https://api.openweathermap.org/`;

  let requete = new XMLHttpRequest();
  requete.open('GET', url);
  requete.responseType = 'json';
  requete.send();

  requete.onload = function() {
    if (requete.readyState === XMLHttpRequest.DONE) {
      if (requete.status === 200) {
        let reponse = requete.response;
        let temperatureNow = reponse.main.temp;
        let summaryNow = reponse.weather.main;
        let cityCurrent = reponse.name;
        document.querySelector('#summary').innerText = summaryNow;
        document.querySelector('#city').innerText = cityCurrent;
        document.querySelector('#temperature_label').innerText = temperatureNow;
      }
    } else {
      alert('Something went wrong, please come back later.');
    }
  }
}

Problem is on summaryNow. cityCurrent and temperatureNow are loading correctly

let temperatureNow = reponse.main.temp;
let summaryNow = reponse.weather.main; //error
let cityCurrent = reponse.name;

I am possibly missing "[" from json to make it load correctly in function. Please let me know what wrong i am doing?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!